package com.suoluo.zenadmin.controllers.api.dest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.suoluo.zenadmin.common.encrypt.EncryptUtil;

//api/dest.do
public class Test {

	public static void main(String[] args) throws IOException {

	
		//测试酒店URL url = new URL("http://localhost:8080/zentravel/api/hotel");
		URL url = new URL("http://localhost:8080/zentravel/api/dest/hotel");
		HttpURLConnection httpConnection = (HttpURLConnection) url
				.openConnection();
		httpConnection.setRequestMethod("POST");
		long time = System.currentTimeMillis();
		String token = "aaaaa";
		StringBuilder builder = new StringBuilder(token);
		builder = builder.append(time);
		String secret = EncryptUtil.md5(builder.toString());
		//特色Id
		//String features = "1,2"; 
		
		//测试酒店StringBuffer buf = new StringBuffer("hotelId=10&secret=");
		StringBuffer buf = new StringBuffer("destId=1&hotelId=7&secret=");
		buf.append(secret).append("&time=").append(time).append("&version=1");

		httpConnection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
		httpConnection.setDoOutput(true);
		httpConnection.setDoInput(true);

		OutputStream os = httpConnection.getOutputStream();
		String value = buf.toString();
		os.write(value.getBytes("utf-8"));
		os.flush();
		os.close();


		if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
			StringBuffer stringBuffer = new StringBuffer();
			try {
				String strCurrentLine;
				BufferedReader reader = new BufferedReader(
						new InputStreamReader(httpConnection.getInputStream()));
				while ((strCurrentLine = reader.readLine()) != null) {
					stringBuffer.append(strCurrentLine).append("\n");
				}
				reader.close();
			} catch (IOException e) {
			}
			System.out.println(stringBuffer);
		}

	}
}
